From 86a2f900ffdb2209ecb66729bc0452a94c6d82f4 Mon Sep 17 00:00:00 2001 From: robertlipe Date: Mon, 11 Feb 2013 03:17:22 +0000 Subject: [PATCH] Add, use an abstraction for testing url and url_link_text in preparation for the day when it's not a string pointer. --- gpsbabel/an1.cc | 2 +- gpsbabel/csv_util.cc | 4 ++-- gpsbabel/defs.h | 2 ++ gpsbabel/easygps.cc | 4 ++-- gpsbabel/garmin_txt.cc | 2 +- gpsbabel/gdb.cc | 6 +++--- gpsbabel/geo.cc | 2 +- gpsbabel/html.cc | 2 +- gpsbabel/kml.cc | 6 +++--- gpsbabel/lmx.cc | 4 ++-- gpsbabel/mmo.cc | 6 +++--- gpsbabel/tmpro.cc | 2 +- gpsbabel/unicsv.cc | 2 +- gpsbabel/vcf.cc | 2 +- 14 files changed, 24 insertions(+), 22 deletions(-) diff --git a/gpsbabel/an1.cc b/gpsbabel/an1.cc index b80f66a53..a2263bacb 100644 --- a/gpsbabel/an1.cc +++ b/gpsbabel/an1.cc @@ -778,7 +778,7 @@ Write_One_AN1_Waypoint(const waypoint* wpt) xfree(extra); } - if (!nourl && wpt->url) { + if (!nourl && wpt->hasLink()) { int len = 7+strlen(wpt->url); char* extra = (char*)xmalloc(len); sprintf(extra, "{URL=%s}", wpt->url); diff --git a/gpsbabel/csv_util.cc b/gpsbabel/csv_util.cc index 9f856ebb9..3cefc34cb 100644 --- a/gpsbabel/csv_util.cc +++ b/gpsbabel/csv_util.cc @@ -1711,7 +1711,7 @@ xcsv_waypt_pr(const waypoint* wpt) strcpy(buff, xcsv_urlbase); off = strlen(xcsv_urlbase); } - if (wpt->url) { + if (wpt->hasLink()) { snprintf(buff + off, sizeof(buff) - off, fmp->printfc, wpt->url); } else { strcpy(buff, (fmp->val && *fmp->val) ? fmp->val : "\"\""); @@ -1720,7 +1720,7 @@ xcsv_waypt_pr(const waypoint* wpt) break; case XT_URL_LINK_TEXT: snprintf(buff, sizeof(buff), fmp->printfc, - (wpt->url_link_text && *wpt->url_link_text) ? wpt->url_link_text : fmp->val); + (wpt->hasLinkText()) ? wpt->url_link_text : fmp->val); break; case XT_ICON_DESCR: writebuff(buff, fmp->printfc, diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index 5a1caf099..9447a56b2 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -540,6 +540,8 @@ public: * members must match struct url_link... */ url_link* url_next; + bool hasLink() const {return url && *url; } + bool hasLinkText() const {return url && *url; } char* url; char* url_link_text; diff --git a/gpsbabel/easygps.cc b/gpsbabel/easygps.cc index 1cdc3820e..11c771cd7 100644 --- a/gpsbabel/easygps.cc +++ b/gpsbabel/easygps.cc @@ -168,11 +168,11 @@ ez_disp(const waypoint* wpt) gbfputc(5, file_out); gbfputpstr(wpt->notes, file_out); } - if (wpt->url_link_text) { + if (wpt->hasLinkText()) { gbfputc(6, file_out); gbfputpstr(wpt->url_link_text, file_out); } - if (1 && wpt->url) { + if (wpt->hasLink()) { gbfputc(9, file_out); gbfputcstr(wpt->url, file_out); } diff --git a/gpsbabel/garmin_txt.cc b/gpsbabel/garmin_txt.cc index 22a66d3b2..12bcd60cb 100644 --- a/gpsbabel/garmin_txt.cc +++ b/gpsbabel/garmin_txt.cc @@ -619,7 +619,7 @@ write_waypt(const waypoint* wpt) country = gt_get_icao_country(GMSD_GET(cc, "")); print_string("%s\t", (country != NULL) ? country : ""); print_date_and_time(wpt->creation_time, 0); - print_string("%s\t", wpt->url ? wpt->url : ""); + print_string("%s\t", wpt->hasLink() ? wpt->url : ""); print_categories(GMSD_GET(category, 0)); gbfprintf(fout, "\r\n"); diff --git a/gpsbabel/gdb.cc b/gpsbabel/gdb.cc index 2227f1705..a6de7878a 100644 --- a/gpsbabel/gdb.cc +++ b/gpsbabel/gdb.cc @@ -457,7 +457,7 @@ read_file_header(void) reclen = FREAD_i32; i = FREAD(buf, reclen + 1); if (global_opts.verbose_status > 0) { - char* name = buf+2; + const char* name = buf+2; if (strstr(name, "SQA") == 0) { name = "MapSource"; } else if (strstr(name, "neaderhi") == 0) { @@ -1375,7 +1375,7 @@ write_waypoint( FWRITE_CSTR(str); /* instruction */ cnt = 0; - if (wpt->url) { + if (wpt->hasLink()) { cnt++; } for (url_next = wpt->url_next; (url_next); url_next = url_next->url_next) @@ -1383,7 +1383,7 @@ write_waypoint( cnt++; } FWRITE_i32(cnt); - if (wpt->url) { + if (wpt->hasLink()) { FWRITE_CSTR(wpt->url); } for (url_next = wpt->url_next; (url_next); url_next = url_next->url_next) diff --git a/gpsbabel/geo.cc b/gpsbabel/geo.cc index c30109f70..0d21ea059 100644 --- a/gpsbabel/geo.cc +++ b/gpsbabel/geo.cc @@ -270,7 +270,7 @@ geo_waypt_pr(const waypoint* waypointp) writer.writeTextElement("type", deficon ? deficon : waypointp->icon_descr); - if (waypointp->url) { + if (waypointp->hasLink()) { writer.writeStartElement("link"); writer.writeAttribute("text ", "Cache Details"); writer.writeCharacters(waypointp->url); diff --git a/gpsbabel/html.cc b/gpsbabel/html.cc index 9e21da9aa..27c192e0c 100644 --- a/gpsbabel/html.cc +++ b/gpsbabel/html.cc @@ -108,7 +108,7 @@ html_disp(const waypoint* wpt) } gbfprintf(file_out, "
\n"); if (strcmp(wpt->description, wpt->shortname)) { - if (wpt->url) { + if (wpt->hasLink()) { char* d = html_entitize(wpt->description); gbfprintf(file_out, "%s", wpt->url, d); xfree(d); diff --git a/gpsbabel/kml.cc b/gpsbabel/kml.cc index 4e403e614..fb797453e 100644 --- a/gpsbabel/kml.cc +++ b/gpsbabel/kml.cc @@ -1448,7 +1448,7 @@ static void kml_geocache_pr(const waypoint* waypointp) xfree(p); } - if (waypointp->url_link_text) { + if (waypointp->hasLinkText()) { p = xml_entitize(waypointp->url_link_text); kml_write_xml(0, "%s\n", p); xfree(p); @@ -1528,11 +1528,11 @@ static void kml_waypt_pr(const waypoint* waypointp) kml_write_xmle("name", waypointp->shortname); // Description - if (waypointp->url && waypointp->url[0]) { + if (waypointp->hasLink()) { char* odesc = xml_entitize(waypointp->url); kml_write_xml(0, "\n"); kml_write_xml(0, "\n"); - if (waypointp->url_link_text && waypointp->url_link_text[0]) { + if (waypointp->hasLinkText()) { char* olink = xml_entitize(waypointp->url_link_text); kml_write_xml(0, "%s]]>", odesc, olink); xfree(olink); diff --git a/gpsbabel/lmx.cc b/gpsbabel/lmx.cc index 66c71deb0..09573ab94 100644 --- a/gpsbabel/lmx.cc +++ b/gpsbabel/lmx.cc @@ -237,12 +237,12 @@ lmx_print(const waypoint* wpt) } lmx_end_tag(0x4A, 3); // coordinates - if (wpt->url && wpt->url[0]) { + if (wpt->hasLink()) { lmx_start_tag(0x65, 3); // mediaLink if (!binary) { gbfputc('\n', ofd); } - if (wpt->url_link_text) { + if (wpt->hasLinkText()) { lmx_write_xml(0x48, wpt->url_link_text, 4); // name } lmx_write_xml(0x67, wpt->url, 4); // url diff --git a/gpsbabel/mmo.cc b/gpsbabel/mmo.cc index bbe234944..b86e5c640 100644 --- a/gpsbabel/mmo.cc +++ b/gpsbabel/mmo.cc @@ -547,7 +547,7 @@ mmo_read_CObjWaypoint(mmo_data_t* data) wpt->notes = xstrdup(cend); } - if (wpt->url) { + if (wpt->hasLink()) { DBG((sobj, "url = \"%s\"\n", wpt->url)); } } else if (*str) { @@ -1013,7 +1013,7 @@ mmo_finalize_rtept_cb(const waypoint* wptref) if (wpt2->notes) { wpt->notes = xstrdup(wpt2->notes); } - if (wpt2->url) { + if (wpt2->hasLink()) { wpt->notes = xstrdup(wpt2->url); } @@ -1310,7 +1310,7 @@ mmo_write_wpt_cb(const waypoint* wpt) gbfputuint16(0, fout); /* extra bytes */ } - if (wpt->url && *wpt->url) { + if (wpt->hasLink()) { str = xstrdup("_FILE_ "); str = xstrappend(str, wpt->url); str = xstrappend(str, "\n"); diff --git a/gpsbabel/tmpro.cc b/gpsbabel/tmpro.cc index 94cb02ff1..58911d0ff 100644 --- a/gpsbabel/tmpro.cc +++ b/gpsbabel/tmpro.cc @@ -220,7 +220,7 @@ tmpro_waypt_pr(const waypoint * wpt) wpt->altitude, colour, icon, - wpt->url ? wpt->url : "" + wpt->hasLink() ? wpt->url : "" ); diff --git a/gpsbabel/unicsv.cc b/gpsbabel/unicsv.cc index 42d8d831f..3d5dc16b4 100644 --- a/gpsbabel/unicsv.cc +++ b/gpsbabel/unicsv.cc @@ -1356,7 +1356,7 @@ unicsv_waypt_enum_cb(const waypoint *wpt) gb_setbit(&unicsv_outp_flags, fld_notes); } } - if (wpt->url && *wpt->url) { + if (wpt->hasLink()) { gb_setbit(&unicsv_outp_flags, fld_url); } if (wpt->creation_time != 0) { diff --git a/gpsbabel/vcf.cc b/gpsbabel/vcf.cc index 9fee87eaa..b0e586684 100644 --- a/gpsbabel/vcf.cc +++ b/gpsbabel/vcf.cc @@ -104,7 +104,7 @@ vcf_disp(const waypoint *wpt) gbfprintf(file_out, "N:%s;%s;;;\n", wpt->description,wpt->shortname); gbfprintf(file_out, "ADR:%c%d %06.3f %c%d %06.3f\n", wpt->latitude < 0 ? 'S' : 'N', abs(latint), 60.0 * (fabs(wpt->latitude) - latint), wpt->longitude < 0 ? 'W' : 'E', abs(lonint), 60.0 * (fabs(wpt->longitude) - lonint)); - if (wpt->url) { + if (wpt->hasLink()) { gbfprintf(file_out, "URL:%s\n", wpt->url); } -- 2.30.2